const required = (msg = '必填项', trigger = ['blur']) => {
  return {
    required: true,
    message: msg,
    trigger: trigger,
  };
};

const maxLength = (max: number, msg?, trigger = ['input', 'focus', 'blur']) => {
  return {
    validator(r, v) {
      if (v.length > max) {
        return new Error(msg || '长度不可大于' + max);
      }
    },
    trigger: trigger,
  };
};

const minLength = (min: number, msg?, trigger = ['input', 'focus', 'blur']) => {
  return {
    validator(r, v) {
      if (v.length < min) {
        return new Error(msg || '长度不可小于' + min);
      }
    },
    trigger: trigger,
  };
};

export { required, maxLength, minLength };
